package ControllerApplication;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import ModelApplication.Sound;
import UtilsApplication.HandleAudioUtil;

public class Sounds {

    private List<Sound> listsSounds;

    private final String pathExamplesSounds = System.getProperty("user.dir") + File.separator + "soundExamples/";
//natural/flute
    //artificial/diff
    public Sounds() {
        listsSounds = new ArrayList<Sound>();
        loadExamplesImages();
    }

    public Sound getSound(int index) {
        if(index < listsSounds.size()) {
            return listsSounds.get( index );
        }
        return null;
    }

    public Sound getLastSound() {
        if(listsSounds.size() > 0) {
            return listsSounds.get( listsSounds.size() - 1 );
        }

        return null;
    }

    public List<String> getAllNameSounds() {
        List<String> names = new ArrayList<String>();
        for(Iterator<Sound> it = listsSounds.iterator(); it.hasNext();) {
            names.add( it.next().getName());
        }

        return names;
    }

    public List<Sound> getAllSounds() {
        return listsSounds;
    }

    public void deteleSound(int index) {
        listsSounds.remove( index );
    }

    public List<String []> getAllInformation() {
        List<String []> information = new ArrayList<String []>();
        for(Iterator<Sound> it = listsSounds.iterator(); it.hasNext();) {
            Sound img = it.next();
            String [] o = new String [4];
            o[0] = img.getName();     
            o[1] = img.getMethodProcessing();
            o[2] = img.getBaseFreqString();
            if(img.getExecutionTime() != null) {
                o[3] = img.getExecutionTime().toString();
            }

            information.add( o );  
        }

        return information;
    }

    public void addSound(Sound sound) {
        listsSounds.add( sound );
    }

    public void addSounds(List<Sound> sound) {
        for(Sound soundVar : sound) {
            listsSounds.add( soundVar );
        }
    }

    private void loadExamplesImages() {
        listsSounds = HandleAudioUtil.loadSounds( pathExamplesSounds );
    }

}
